package com.eightbears.beboy.adapter;

import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.eightbears.beboy.R;
import com.eightbears.beboy.base.util.CommonUtils;
import com.eightbears.beboy.entity.ReserveEntity;
import com.eightbears.beboy.entity.UserReserveEntity;

public class UserReserveListAdapter extends BaseQuickAdapter<UserReserveEntity.ReserveInfo, BaseViewHolder> {

    private TextView tv_reserve_title;
    private TextView tv_status;
    private TextView tv_reserve_info;
    private TextView tv_call;
    private LinearLayout ll_bottom, ll_fail;

    public UserReserveListAdapter() {
        super(R.layout.item_user_reserve, null);
    }

    @Override
    protected void convert(BaseViewHolder baseViewHolder, UserReserveEntity.ReserveInfo reserveInfo) {
        tv_reserve_title = baseViewHolder.getView(R.id.tv_reserve_title);
        tv_status = baseViewHolder.getView(R.id.tv_status);
        tv_reserve_info = baseViewHolder.getView(R.id.tv_reserve_info);
        ll_bottom = baseViewHolder.getView(R.id.ll_bottom);
        tv_call = baseViewHolder.getView(R.id.tv_call);
        TextView tv_result_info = baseViewHolder.getView(R.id.tv_result_info);
        ll_fail = baseViewHolder.getView(R.id.ll_fail);

        replaceView();

        baseViewHolder.setText(R.id.tv_shop_name, reserveInfo.getShop().getTitle())
                .setText(R.id.tv_publish_date, CommonUtils.TimeStamp2Date(reserveInfo.getCreated_at(), "yyyy-MM-dd HH:mm"))
                .setText(R.id.tv_num, reserveInfo.getNum())
                .setText(R.id.tv_date, CommonUtils.TimeStamp2Date(reserveInfo.getTime(), "yyyy-MM-dd HH:mm"))
                .setText(R.id.tv_phone, reserveInfo.getMobile())
                .setText(R.id.tv_result_info, reserveInfo.getComment())
                .addOnClickListener(R.id.tv_call)
                .addOnClickListener(R.id.tv_reserve_info);

        switch (reserveInfo.getStatus()) {
            case ReserveEntity.STATUS_WAIT:
                showWait();
                break;
            case ReserveEntity.STATUS_AGREE:
                showSuccess();
                break;
            case ReserveEntity.STATUS_REFUSE:
                showFail();
                break;
        }
    }

    private void replaceView(){
        ll_bottom.setVisibility(View.GONE);
        tv_status.setVisibility(View.GONE);
        tv_call.setVisibility(View.GONE);
        ll_fail.setVisibility(View.GONE);
    }

    private void showWait() {
        tv_reserve_title.setText("预定回执");
        tv_status.setText("已提交");
        tv_reserve_info.setText("如果商家未及时回应, 请与商家联系");
        tv_status.setVisibility(View.VISIBLE);
        ll_bottom.setVisibility(View.VISIBLE);
        tv_call.setVisibility(View.VISIBLE);
    }

    private void showSuccess() {
        tv_reserve_title.setText("预定成功");
        ll_bottom.setVisibility(View.VISIBLE);
        tv_reserve_info.setText("查看商家详情 >");

    }

    private void showFail() {
        tv_reserve_title.setText("预定失败");
        ll_bottom.setVisibility(View.VISIBLE);
        tv_reserve_info.setText("跟多预定请与商家联系 >");
        tv_call.setVisibility(View.VISIBLE);
        ll_fail.setVisibility(View.VISIBLE);
    }
}
